import React from 'react'
import PropTypes from 'prop-types'
import {Col, Form, Input, Modal, Row} from 'antd'

const FormItem = Form.Item

const formItemLayout = {
  labelCol: {span: 4},
  wrapperCol: {span: 20},
}

const modal = ({
                 item = {},
                 onOk,
                 disable,
                 form: {
                   getFieldDecorator,
                   validateFields,
                   getFieldsValue,
                 },
                 ...modalProps
               }) => {
  const handleOk = () => {
    validateFields((errors) => {
      if (errors) {
        return
      }
      const data = {
        ...getFieldsValue(),
        key: item.key,
      }
      onOk(data)
    })
  }

  console.log(item)

  const modalOpts = {
    ...modalProps,
    onOk: handleOk,
  }

  return (
    <Modal {...modalOpts}>
      <Form layout="horizontal">
        <Row gutter={24}>
          <Col span={24}>
            <FormItem {...formItemLayout} label="请输入">
              {getFieldDecorator('reason', {
                rules: [{required: true, message: '请输入处理理由'}],
              })(<Input disabled={disable} placeholder="请输入处理理由"/>)}
              {getFieldDecorator('id', {initialValue: item.id})(<input type='hidden'/>)}
            </FormItem>
          </Col>
        </Row>
      </Form>
    </Modal>
  )
}

modal.propTypes = {
  form: PropTypes.object.isRequired,
  type: PropTypes.string,
  item: PropTypes.object,
  onOk: PropTypes.func,
}

export default Form.create()(modal)
